home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / quicktime / all java / quicktime for java / musicmixer / src / mixer / mc / mixermovie.java < prev    next >
Encoding:
Java Source  |  2000-06-23  |  3.6 KB  |  117 lines

  1. /*
  2.  * QuickTime for Java SDK Sample Code
  3.  
  4.    Usage subject to restrictions in SDK License Agreement
  5.  * Copyright: © 1996-1999 Apple Computer, Inc.
  6.  
  7.  */
  8. package mixer.mc;
  9.  
  10. import mixer.display.*;
  11.  
  12. import quicktime.std.movies.*;
  13. import quicktime.std.movies.media.*;
  14. import quicktime.app.audio.*;
  15. import quicktime.app.players.*;
  16. import quicktime.*;
  17. import quicktime.std.*;
  18. import java.util.*;
  19.  
  20. import javax.swing.*;
  21. import java.awt.*;
  22.  
  23. /** This is the first class involved in making the mixer.  It is capable of making the
  24.  *  JComponent for the master control of the movie.
  25.  */
  26. public class MixerMovie implements MixerComponents {
  27.     private Vector audioMedia;
  28.     private AudioSpec master;
  29.     
  30.     /** This constructor will create a Mixer for a movie in a QTPlayer.
  31.      *  @param pl the QTPlayer with the movie to mix
  32.      *  The assumption is that the Player will serve as the master control for the movie
  33.      */
  34.     public MixerMovie (QTPlayer pl) throws QTException {
  35.         this (pl.getMovieController().getMovie(), pl);
  36.     }
  37.     
  38.     /** This constructor will create a Mixer for a movie in a MoviePlayer.
  39.      *  @param pl the MoviePlayer with the movie to mix
  40.      *  The assumption is that the Player will serve as the master control for the movie
  41.      */
  42.     public MixerMovie (MoviePlayer pl) throws QTException {
  43.         this (pl.getMovie(), pl);
  44.     }
  45.  
  46.     private MixerMovie (Movie m, AudioSpec mast) throws QTException {
  47.         master = mast;
  48.         m.preroll (0, 1.0F);
  49.         audioMedia = getAudioTracks (m);
  50.     }
  51.         
  52.  
  53.     /** This method will return the master control for the movie.
  54.      *  @return the AudioSpec object that serves as the master control for the movie
  55.      */
  56.     public AudioSpec getMaster() {
  57.         return master;
  58.     }
  59.     
  60.     /** This method returns all of the MixerComponents that are contained inside of
  61.      *  the movie.
  62.      *  @return the array of MixerComponents found in the movie
  63.      */
  64.     public MixerComponents[] getChannels() {
  65.         if (audioMedia == null)
  66.             return null;
  67.         MixerComponents[] ar = new MixerComponents [audioMedia.size()];
  68.         for (int i = 0; i < ar.length; i++)
  69.             ar[i] = (MixerComponents)audioMedia.elementAt(i);
  70.         return ar;
  71.     }
  72.     
  73.     /** This method creates the component that needs to be given to the user to edit
  74.      *  the channels in this movie.
  75.      *  @return the component with the controls necessary to mix the channels
  76.      */
  77.     public JComponent makeEditComponent () throws QTException {
  78.         JPanel balance = new JPanel ();
  79.         balance.setLayout (new BorderLayout());
  80.         balance.add (new SoloableChannels (getChannels()), "Center");
  81.         balance.add (new Label ("Tracks"), "North");
  82.         return balance;
  83.     }
  84.     
  85.     /** Returns whether or not this movie contains tracks which are editable.  This
  86.      *  should be true if there are any movie or sound tracks in the movie
  87.      *  @return the editable state of the movie
  88.      */
  89.     public boolean isEditable() { 
  90.         return getChannels() != null;
  91.     }
  92.     
  93.     /* This method gets all of the audio tracks out of a movie. */
  94.     private static Vector getAudioTracks (Movie mov) throws QTException {
  95.         int numTracks = mov.getTrackCount();
  96.         Vector v = new Vector(numTracks);
  97.         Track curTrack;
  98.         Media trackMedia;
  99.         
  100.         // add the audio media from each track
  101.         for (int i = 1; i <= numTracks; i++) {
  102.             curTrack = mov.getIndTrack(i);
  103.             trackMedia = Media.getTrackMedia(curTrack);
  104.             if (trackMedia instanceof SoundMedia) 
  105.                 v.addElement(new MixerSoundTrack ((SoundMedia) trackMedia));
  106.             else if (trackMedia instanceof MusicMedia)
  107.                 v.addElement(new MixerMusicTrack (mov, (MusicMedia) trackMedia));
  108.         }
  109.         
  110.         if (v.size() == 0)
  111.             return null;
  112.         
  113.         v.setSize (v.size());
  114.         return v;
  115.     }
  116. }
  117.